package br.com.cnpv.modelo.bo;

import java.util.List;

import org.hibernate.Session;

import br.com.cnpv.modelo.acesso.idao.IModeloDAO;
import br.com.cnpv.modelo.dao.ModeloDAO;
import br.com.cnpv.modelo.entity.Modelo;
import br.com.cnpv.util.HibernateUtil;

public class ModeloBO extends HibernateUtil
{
	public static ModeloBO INSTANCE;
	
	public static ModeloBO getInstance()
	{
		if(INSTANCE == null)
		{
			synchronized (ModeloBO.class) {
				INSTANCE = new ModeloBO();
			}
		}
		return INSTANCE;
	}

	public List<Modelo> listarPorMarca(int idMarca) throws Exception
	{
		Session session = null;
		List<Modelo> list = null;
		try
		{
			session = currentSession();
			IModeloDAO dao = new ModeloDAO();
			list = dao.listarPorMarca(idMarca, session);
		}catch(Exception e)
		{
			throw new Exception(e);
		}finally
		{
			if(session != null)
			{
				session.flush();
				session.clear();
			}
			closeSession();
		}
		return list;
	}
}